package com.jiazhong.example.project.bookstore.backend.controller;

import com.jiazhong.example.project.bookstore.backend.service.PowerService;
import com.jiazhong.example.project.bookstore.commons.bean.Power;
import com.jiazhong.example.project.bookstore.commons.util.JsonResult;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/power")
public class PowerController {
    @Resource
    private PowerService powerService;

    @GetMapping
    public JsonResult find() {
        return powerService.findAllPower();
    }

    @GetMapping("/{id}")
    public JsonResult find(@PathVariable("id") String id) {
        return powerService.findPowerByUserId(id);
    }

    @PostMapping
    public JsonResult update(String userId, String[] powers) {
        return powerService.updateUserPowers(userId, Arrays.asList(powers));
    }
}
